<template>
	<view class="good-list">
		<!-- 人气 -->
		<template v-if="type==0">
			<view class="g-top">
				<view>{{$t('yuce.yonghuming')}}</view>
				<view>{{$t('yuce.jinscbs')}}</view>
			</view>
			<view class="li" v-for="(item,index) in list" :key="index" @click="navigatorTo(item)">
				<view class="left">
					<view class="num">{{index+1}}</view>
					<image class="image" :src="item.avatar||'https://www.soccerpet.com/static/img/default_photo.png'"></image>
					<view class="textwarp">
						<view class="text1">{{item.nickname}}</view>
						<view class="text2">
							<image :src="computresult(text)" style="width: 20px;height: 20px;border-radius: 50%;" 
							v-for="(text,index) in item.tenResult" :key="index"></image>
						</view>
					</view>
				</view>
				<view class="right">
					<view class="r-btn" @click.stop="attention(item)" :class="{myFollow:myFollowList.includes(item.uid)}">
					{{myFollowList.includes(item.uid)==true?$t('yuce.yiguanzhu'):$t('yuce.guanzhu')}}</view>
					<!-- <view>{{item.attentionNum}}人关注</view> -->
				</view>
			</view>
		</template>
		<!-- 周榜月榜 -->
		<template v-if="type==1||type==2">
			<view class="yuezhou">
				<view style="width: 130rpx;"></view>
				<view style="width:180rpx;">{{$t('yuce.yonghuming')}}</view>
				<view style="display: flex;">
					<view style="width: 76px;">{{$t('yuce.honghei')}}</view>
					<view>{{$t('yuce.mingzhonglv')}}</view>
				</view>
			</view>
			<view class="li" v-for="(item,index) in list" :key="index"  @click="navigatorTo(item)">
				<view class="left">
					<view class="num">{{index+1}}</view>
					<image class="image" :src="item.avatar||'https://www.soccerpet.com/static/img/default_photo.png'"></image>
					<view class="yuezhouText">{{item.nickname}}</view>
					<view class="yuezhou-right">
						<view style="width:130rpx"><text style="color: #f04545;">{{item.win}}</text>/<text style="color: #2ca31f;">{{item.lose}}</text></view>
						<view>
							<text style="color: #f04545;">{{item.winrate}}%</text>
						</view>
					</view>
				</view>
				<view class="right">
					<view class="r-btn" @click.stop="attention(item)" :class="{myFollow:myFollowList.includes(item.uid)}">
					{{myFollowList.includes(item.uid)==true?$t('yuce.yiguanzhu'):$t('yuce.guanzhu')}}</view>
					<!-- <view>{{item.attentionNum}}人关注</view> -->
				</view>
			</view>
		</template>
		<!-- 连红 -->
		<template v-if="type==3">
			<view class="li" v-for="(item,index) in list" :key="index" @click="navigatorTo(item)">
				<view class="left">
					<view class="num">{{index+1}}</view>
					<image class="image" :src="item.avatar"></image>
					<view class="textwarp">
						<view class="text1">{{item.nickname}}</view>
						<view class="text" style="font-size: 12px;display: flex;">
							{{$t('yuce.dangqian')}}：<text style="color: #f04545;margin-right: 10px;">{{item.nowWin}}</text>{{$t('yuce.lianhong')}},
							{{$t('yuce.lishizuigao')}}：<text style="color: #f04545;margin-right: 10px;">{{item.maxWin}}</text>{{$t('yuce.lianhong')}}
						</view>
					</view>
				</view>
				<view class="right" style="position: absolute;right: 10px;top: 10px;">
					<view class="r-btn" @click.stop="attention(item)" :class="{myFollow:myFollowList.includes(item.uid)==true}">
					{{myFollowList.includes(item.uid)==true?$t('yuce.yiguanzhu'):$t('yuce.guanzhu')}}</view>
					<!-- <view>{{item.attentionNum}}人关注</view> -->
				</view>
			</view>
		</template>
		
	</view>
</template>

<script>
	let that
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		computed: {
			...mapGetters(['userInfo', 'api']),
			computresult(){
				return (result,type)=>{
					if(result=='1'){
						return '../../../static/image/yuce/hong.png'
					}else if(result=='2'){
						return '../../../static/image/yuce/ping.png'
					}else if(result=='-1'){
						return '../../../static/image/yuce/hei.png'
					}
				}
			}
		},
		props: {
			list: {
				type: [Array, Object],
				default () {
					return {}
				}
			},
			myFollow: {
				type:Array,
				default () {
					return []
				}
			},
			type: {
				type: Number,
				default () {
					return 1
				}
			}
		},
		data() {
			return {
				dataList: [],
				myFollowList:[],
			}
		},
		watch:{
			myFollow:{
				handler(val, oldVal){
					this.myFollowList = JSON.parse(JSON.stringify(val))
					console.log('监听',this.myFollowList);
				},
				deep: true
			}
		},
		mounted() {
			that = this
		},
		methods: {
			navigatorTo(item) {
				this.$emit("clickRow", item)
			},
			//关注或取关
			attention(row){
				let type = 1
				if(this.myFollowList.includes(row.uid)==true){
					type = 0
				}else{
					type = 1
				}
				if(this.userInfo.id){
					let params={
						uid:row.uid,
						type:type//类型 1关注  0取消关注
					}
					uni.$u.http.post(this.api.api_v1_user_attention, params).then(res => {
						if(res.code==200){
							uni.showToast({
								title: res.msg
							});
							if(type == 1){
								this.myFollowList.push(row.uid)
							}else{
								this.myFollowList = this.myFollowList.filter(item=>item!=row.uid)
							}
							
						}
					})
				}else{
					
					uni.navigateTo({
						url: '/pages/login/login?from=/pages/tabBar/LIST/LIST',
						success: res => {
							setTimeout(()=>{
								uni.showToast({
									title: 'please log in first',
									icon:"none"
								});
							},1000)
						},
						fail: () => {},
						complete: () => {}
					});
				}
				
			},
		}

	}
</script>

<style lang="scss">
	.good-list {
		padding: 0 10px;
		font-size: 14px;

		.g-top {
			display: flex;
			justify-content: space-around;
			padding: 10px;
		}
		.yuezhou{
			display: flex;padding: 10px;
			.yuezhouleft{
				flex: 1;text-align: center;
			}
			.yuezhouright{
				display: flex;justify-content: space-between;width: 340rpx;
			}
		}
		.yuezhouText{
			width: 200rpx;
		}
		.yuezhou-right{
			display: flex;
		}

		.li {
			display: flex;margin-bottom: 10px;
			align-items: center;
			padding: 10px;
			justify-content: space-between;
			background-color: #242448;
			border-radius: 4px;
			position: relative;
			.left {
				display: flex;
				align-items: center;

				.image {
					width: 40px;
					height: 40px;
					border-radius: 50%;
					margin: 0 10px;
				}

				.textwarp {
					line-height: 22px;min-width: 420rpx;

					.text2 {
						color: red;
					}
				}
			}

			.right {
				font-size: 12px;

				.r-btn {
					background-color: #FF6B00;
					border-radius: 5px;
					text-align: center;
					width: 60px;
					height: 24px;
					line-height: 24px;
					margin-bottom: 2px;
				}
				.myFollow{
					background-color: #c5c5c5;
				}
			}


		}
	}
</style>